"""
内容：ROC曲线与P-R曲线
日期：2020年6月28日
作者：Howie
"""
from numpy import array
import matplotlib.pyplot as plt

# 以10%为单位调整阈值，敏感度和特异度随之变化
plt.figure(0)
sens_F = array([1.0, 1.0, 1.0, 1.0, 0.75, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0])
spec_F = array([0.0, 0.16, 0.5, 0.66, 0.66, 0.66, 0.83, 1.0, 1.0, 1.0, 1.0])

sens_G = array([1.0, 1.0, 0.75, 0.75, 0.5, 0.5, 0.5, 0.5, 0.25, 0.25, 0.0])
spec_G = array([0.0, 0.33, 0.33, 0.5, 0.5, 0.66, 0.66, 0.83, 0.83, 1.0, 1.0])

plt.title('Receiver Operating Characteristic')
plt.xlabel('False Positive Rate(1 - Specificity)')
plt.ylabel('True Positive Rate(Sensitivity)')

plt.plot(1 - spec_F, sens_F, 'b', label='Model F')
plt.plot(1 - spec_G, sens_G, 'g', label='Model G')

plt.plot([0, 1], [1, 1], 'y--')
plt.plot([0, 1], [0, 1], 'r--')

plt.legend(loc='lower right')

plt.savefig('./logs/ROC Curve.pdf')
plt.show()

plt.figure(1)
precision_F = array([0.33, 0.38, 0.45, 0.55, 0.57,
                     0.40, 0.66, 1.0, 1.0, 1.0, 1.0])
recall_F = array([1.0, 1.0, 1.0, 1.0, 0.8, 0.4, 0.4, 0.4, 0.4, 0.2, 0.0])

precision_G = array([0.33, 0.38, 0.36, 0.37, 0.33,
                     0.40, 0.33, 0.5, 1.0, 1.0, 1.0])
recall_G = array([1.0, 1.0, 0.8, 0.6, 0.4, 0.4, 0.2, 0.2, 0.2, 0.2, 0.0])

plt.title('Precision-Recall Graph')
plt.xlabel('Recall')
plt.ylabel('Precision')

plt.plot(recall_F, precision_F, 'b', label='Model F')
plt.plot(recall_G, precision_G, 'g', label='Model G')

plt.legend(loc='upper right')

plt.savefig('./logs/P-R Curve.pdf')
plt.show()
